package com.hns.can.mainte.web;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hns.can.base.entity.SysUserEntity;
import com.hns.can.common.domain.GridPage;
import com.hns.can.common.service.CommonInitParamService;
import com.hns.can.common.vo.CommonParamsVo;
import com.hns.can.common.web.BaseController;
import com.hns.can.mainte.service.VMSStatusService;
import com.hns.can.mainte.vo.VMSStatusVo;
import com.hns.frame.mybatis.Pagination;
import com.hns.tool.export.ExportUtil;
import com.hns.tool.pub.DateTool;

/**
 * 整车控制Controller
 * @author:zhangzq
 * @email:
 * @version Revision 2.0.0
 */
@Controller
@RequestMapping("/vmsStatus")
public class VMSStatusController extends BaseController{
	
	final private String[] headerNames = new String[]{"车牌号","运营线路","所属机构","采集时间","电机控制器输入电流","电机控制器输入电压","电机转速","司机加速踏板","司机制动踏板","驱动系统状态"};
	final private String[] headerFields = new String[]{"licPltNo", "lineName", "organName", "rcrdTime", "eltMhyCtrlInEltCrt", "eltMhyCtrlInVtg", "eltMhyRtteSpd","drvRevupPedal","drvBrakPedal","driveStmSt"};
	
	@Autowired
	private VMSStatusService vmsStatusService;
	@Autowired
    private CommonInitParamService commonInitParamService;
	
	/**
	 * 分页查询整车控制数据
	 * @param params
	 * @return
	 * @throws Exception
	 * @author:zhangzq
	 * @email:
	 */
    @RequestMapping("/SearchVMSStatus")
    @ResponseBody
	public Object SearchVMSStatus(CommonParamsVo params) throws Exception {
    	SysUserEntity user = this.getCurrentUser().getUser();
		commonInitParamService.initParamsLimitCar(params,user,Arrays.asList("T_COMM_VEHICLE_CTRL_ST_INFO"));
        Pagination page = vmsStatusService.searchVMSStatus(params);
        GridPage grid = new GridPage(page);
        return this.getReturnResult(grid);
	}
    
    /**
     * 导出整车控制数据Excel文件
     * @param params
     * @param response
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportVMSStatusExcel")
    public void exportVMSStatusExcel(CommonParamsVo params,HttpServletResponse response) throws Exception {
        List<VMSStatusVo> list = getVMSStatusData(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "excel", "VMSStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "整车控制数据");
    }
    
    /**
     * 导出整车控制数据Pdf文件
     * @param params
     * @param response
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
    @RequestMapping("/exportVMSStatusPdf")
    public void exportVMSStatusPdf(CommonParamsVo params, HttpServletResponse response) throws Exception {
        List<VMSStatusVo> list = getVMSStatusData(params);
        ExportUtil.exportFiles(Arrays.asList(headerNames), Arrays.asList(headerFields), list, response, "pdf", "VMSStatus"+DateTool.getCurrentSysDate("yyyyMMddHHmmss"), "整车控制数据");
    }
    
    /**
     * 整车控制数据用于导出
     * @param params
     * @return
     * @throws Exception
     * @author:zhangzq
     * @email:
     */
	private List<VMSStatusVo> getVMSStatusData(CommonParamsVo params) throws Exception {
		SysUserEntity user = this.getCurrentUser().getUser();
		commonInitParamService.initParamsLimitCar(params, user, Arrays.asList("T_COMM_VEHICLE_CTRL_ST_INFO"));
        List<VMSStatusVo> list = vmsStatusService.getVMSStatusData(params);
        return list;
    }
}
